home *** CD-ROM | disk | FTP | other *** search
- // SSnowflakes.cpp: Implementierung der Klasse SSnowflakes.
- //
- //////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
-
- #include "SSnowflakes.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
-
- #define MAX_X_VALUE 50
- #define MAX_Y_VALUE 25
- #define MAX_Z_VALUE 50
-
- #define MIN_Y_VALUE -15.0f
-
- //////////////////////////////////////////////////////////////////////
- // Konstruktion/Destruktion
- //////////////////////////////////////////////////////////////////////
-
- SSnowflakes::SSnowflakes()
- {
- snowFlakes = new SnowFlake[MAX_SNOWFLAKES];
- }
-
- SSnowflakes::~SSnowflakes()
- {
- delete[] snowFlakes;
- }
-
- void SSnowflakes::create(STexture* tex)
- {
- texture = tex;
-
- for (int i = 0; i < MAX_SNOWFLAKES; i += 1)
- {
- snowFlakes[i].position[0] = float(rand() % MAX_X_VALUE*10)/10.0f - float(rand() % MAX_X_VALUE*10)/10.0f;
- snowFlakes[i].position[1] = float(rand() % MAX_Y_VALUE*10)/10.0f-2.0f;
- snowFlakes[i].position[2] = -float(rand() % MAX_Z_VALUE*10)/10.0f;
-
- snowFlakes[i].rotation[0] = float(rand() % 360);
- snowFlakes[i].rotation[1] = float(rand() % 360);
- snowFlakes[i].rotation[2] = float(rand() % 360);
-
- snowFlakes[i].speed = float((rand() % 5) +1)/200;
- }
-
- }
-
- void SSnowflakes::update(float frametime)
- {
- glEnable(GL_BLEND);
-
- texture->select();
-
- for (int i = 0; i < MAX_SNOWFLAKES; i += 1)
- {
- SnowFlake& thisOne = snowFlakes[i];
-
- glPushMatrix();
-
- glTranslatef(thisOne.position[0],
- thisOne.position[1],
- thisOne.position[2]);
-
- /*glRotatef(1.0f,thisOne.rotation[0],thisOne.rotation[1],
- thisOne.rotation[2]);*/
-
- glRotatef(thisOne.rotation[0],1.0,0.0,0.0);
- glRotatef(thisOne.rotation[1],0.0,1.0,0.0);
- glRotatef(thisOne.rotation[2],0.0,0.0,1.0);
-
-
- glBegin(GL_QUADS);
- glColor3f(1.0,1.0,1.0);
- glTexCoord2f(0.0,1.0); glVertex3f(-0.5,0.5,0.0);
- glTexCoord2f(1.0,1.0); glVertex3f(0.5,0.5,0.0);
- glTexCoord2f(1.0,0.0); glVertex3f(0.5,-0.5,0.0);
- glTexCoord2f(0.0,0.0); glVertex3f(-0.5,-0.5,0.0);
- glEnd();
-
- thisOne.position[1] -= thisOne.speed*frametime;
-
- thisOne.rotation[0] += 0.10f*frametime;
- thisOne.rotation[1] += 0.10f*frametime;
- thisOne.rotation[2] += 0.10f*frametime;
-
- if (thisOne.position[1] <= MIN_Y_VALUE)
- {
- thisOne.position[0] = float(rand() % MAX_X_VALUE*10)/10 - float(rand() % MAX_X_VALUE*10)/10;
- thisOne.position[1] = MAX_Y_VALUE;
- thisOne.position[2] = -float(rand() % MAX_Z_VALUE*10)/10;
-
- thisOne.rotation[0] = float(rand() % 360);
- thisOne.rotation[1] = float(rand() % 360);
- thisOne.rotation[2] = float(rand() % 360);
-
- thisOne.speed = float((rand() % 10) +1)/100.0f;
- }
-
- glPopMatrix();
- }
-
- glDisable(GL_BLEND);
- }
-